// Copyright Project Harbor Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//    http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package all

import (
	"encoding/json"

	v1 "github.com/goharbor/harbor/src/pkg/scan/rest/v1"
	"github.com/pkg/errors"
)

// CheckInData is designed for checking the data generated by the scan all job.
type CheckInData struct {
	Artifacts []*v1.Artifact `json:"artifacts"`
	Requester string         `json:"requester"`
}

// ToJSON marshals `CheckInData` to JSON str
func (c *CheckInData) ToJSON() (string, error) {
	data, err := json.Marshal(c)
	if err != nil {
		return "", errors.Wrap(err, "ToJSON : CheckInData")
	}

	return string(data), nil
}

// FromJSON unmarshal give bytes to `CheckInData`
func (c *CheckInData) FromJSON(data []byte) error {
	if err := json.Unmarshal(data, c); err != nil {
		return errors.Wrap(err, "FromJSON : CheckInData")
	}

	return nil
}
